package com.sicheng.metadata.se.exp.third;

import org.junit.Test;

import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/10/21 16:14
 */
public class Ex3 {

    @Test
    public void test1() {
        int i = 1;
        double result = 0;
        while (i <= 20) {
            result += 1.0 / factorial(i);
            i++;
        }

        System.out.println(result);
    }


    public int factorial(int n) {
        if (n == 0 || n == 1)
            return 1;
        else
            return n * factorial(n - 1);
    }


    @Test
    public void test2() {

        int[][] arr = new int[3][45];
        for (int[] is : arr) {
            for (int i = 0; i < is.length; i++) {
                is[i] = (int) (Math.random() * 100);
            }
        }

        int sum=0;
        //25，35，45
        for (int i = 0; i < 25; i++) {
            sum+=arr[0][i];
            System.err.print(arr[0][i] + " ");
        }
        System.err.println();
        for (int i = 0; i < 35; i++) {
            sum+=arr[1][i];
            System.err.print(arr[1][i] + " ");
        }
        System.err.println();
        for (int i = 0; i < 45; i++) {
            sum+=arr[2][i];
            System.err.print(arr[2][i] + " ");
        }
        System.err.println();


        System.err.println("sum="+sum);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String myString= sc.nextLine();
        System.out.println("primaryLen="+myString.length());
        myString = myString.replaceAll("\\s*|\t|\r|\n", "");
        System.out.println(myString);
        System.out.println("len="+myString.length());


        System.err.println("输入number,IP,URL");
        String number = sc.nextLine();
        String IP = sc.nextLine();
        String URL = sc.nextLine();


        String matchNum="^(\\-|\\+)?\\d+(\\.\\d+)?$";
        String matchIP="((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}";
        String matchURL="^(http://)?([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";

        System.out.println("matchNum:"+number.matches(matchNum));
        System.out.println("matchIp:"+IP.matches(matchIP));
        System.out.println("matchURL:"+URL.matches(matchURL));


    }

    @Test
    public void test3(){

    }
}
